<!doctype html>
<html>
  <head>
    <!-- MathJax -->
    <script type="text/javascript"
      src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
    </script>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <title>
      Caffe | Inner Product / Fully Connected Layer
    </title>

    <link rel="icon" type="image/png" href="/images/caffeine-icon.png">

    <link rel="stylesheet" href="/stylesheets/reset.css">
    <link rel="stylesheet" href="/stylesheets/styles.css">
    <link rel="stylesheet" href="/stylesheets/pygment_trac.css">

    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <!--[if lt IE 9]>
    <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
  </head>
  <body>
  <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-46255508-1', 'daggerfs.com');
    ga('send', 'pageview');
  </script>
    <div class="wrapper">
      <header>
        <h1 class="header"><a href="/">Caffe</a></h1>
        <p class="header">
          Deep learning framework by <a class="header name" href="http://bair.berkeley.edu/">BAIR</a>
        </p>
        <p class="header">
          Created by
          <br>
          <a class="header name" href="http://daggerfs.com/">Yangqing Jia</a>
          <br>
          Lead Developer
          <br>
          <a class="header name" href="http://imaginarynumber.net/">Evan Shelhamer</a>
        <ul>
          <li>
            <a class="buttons github" href="https://github.com/BVLC/caffe">View On GitHub</a>
          </li>
        </ul>
      </header>
      <section>

      <h1 id="inner-product--fully-connected-layer">Inner Product / Fully Connected Layer</h1>

<ul>
  <li>Layer type: <code class="highlighter-rouge">InnerProduct</code></li>
  <li><a href="http://caffe.berkeleyvision.org/doxygen/classcaffe_1_1InnerProductLayer.html">Doxygen Documentation</a></li>
  <li>Header: <a href="https://github.com/BVLC/caffe/blob/master/include/caffe/layers/inner_product_layer.hpp"><code class="highlighter-rouge">./include/caffe/layers/inner_product_layer.hpp</code></a></li>
  <li>CPU implementation: <a href="https://github.com/BVLC/caffe/blob/master/src/caffe/layers/inner_product_layer.cpp"><code class="highlighter-rouge">./src/caffe/layers/inner_product_layer.cpp</code></a></li>
  <li>
    <p>CUDA GPU implementation: <a href="https://github.com/BVLC/caffe/blob/master/src/caffe/layers/inner_product_layer.cu"><code class="highlighter-rouge">./src/caffe/layers/inner_product_layer.cu</code></a></p>
  </li>
  <li>Input
    <ul>
      <li><code class="highlighter-rouge">n * c_i * h_i * w_i</code></li>
    </ul>
  </li>
  <li>Output
    <ul>
      <li><code class="highlighter-rouge">n * c_o * 1 * 1</code></li>
    </ul>
  </li>
  <li>
    <p>Sample</p>

    <div class="highlighter-rouge"><pre class="highlight"><code>layer {
  name: "fc8"
  type: "InnerProduct"
  # learning rate and decay multipliers for the weights
  param { lr_mult: 1 decay_mult: 1 }
  # learning rate and decay multipliers for the biases
  param { lr_mult: 2 decay_mult: 0 }
  inner_product_param {
    num_output: 1000
    weight_filler {
      type: "gaussian"
      std: 0.01
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
  bottom: "fc7"
  top: "fc8"
}
</code></pre>
    </div>
  </li>
</ul>

<p>The <code class="highlighter-rouge">InnerProduct</code> layer (also usually referred to as the fully connected layer) treats the input as a simple vector and produces an output in the form of a single vector (with the blob’s height and width set to 1).</p>

<h2 id="parameters">Parameters</h2>

<ul>
  <li>Parameters (<code class="highlighter-rouge">InnerProductParameter inner_product_param</code>)
    <ul>
      <li>Required
        <ul>
          <li><code class="highlighter-rouge">num_output</code> (<code class="highlighter-rouge">c_o</code>): the number of filters</li>
        </ul>
      </li>
      <li>Strongly recommended
        <ul>
          <li><code class="highlighter-rouge">weight_filler</code> [default <code class="highlighter-rouge">type: 'constant' value: 0</code>]</li>
        </ul>
      </li>
      <li>Optional
        <ul>
          <li><code class="highlighter-rouge">bias_filler</code> [default <code class="highlighter-rouge">type: 'constant' value: 0</code>]</li>
          <li><code class="highlighter-rouge">bias_term</code> [default <code class="highlighter-rouge">true</code>]: specifies whether to learn and apply a set of additive biases to the filter outputs</li>
        </ul>
      </li>
    </ul>
  </li>
  <li>From <a href="https://github.com/BVLC/caffe/blob/master/src/caffe/proto/caffe.proto"><code class="highlighter-rouge">./src/caffe/proto/caffe.proto</code></a>:</li>
</ul>

<figure class="highlight"><pre><code class="language-protobuf" data-lang="protobuf"><span class="kd">message</span> <span class="nc">InnerProductParameter</span> <span class="p">{</span>
  <span class="k">optional</span> <span class="kt">uint32</span> <span class="na">num_output</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="c1">// The number of outputs for the layer
</span>  <span class="k">optional</span> <span class="kt">bool</span> <span class="na">bias_term</span> <span class="o">=</span> <span class="mi">2</span> <span class="p">[</span><span class="k">default</span> <span class="o">=</span> <span class="kc">true</span><span class="p">];</span> <span class="c1">// whether to have bias terms
</span>  <span class="k">optional</span> <span class="n">FillerParameter</span> <span class="na">weight_filler</span> <span class="o">=</span> <span class="mi">3</span><span class="p">;</span> <span class="c1">// The filler for the weight
</span>  <span class="k">optional</span> <span class="n">FillerParameter</span> <span class="na">bias_filler</span> <span class="o">=</span> <span class="mi">4</span><span class="p">;</span> <span class="c1">// The filler for the bias
</span>
  <span class="c1">// The first axis to be lumped into a single inner product computation;
</span>  <span class="c1">// all preceding axes are retained in the output.
</span>  <span class="c1">// May be negative to index from the end (e.g., -1 for the last axis).
</span>  <span class="k">optional</span> <span class="kt">int32</span> <span class="na">axis</span> <span class="o">=</span> <span class="mi">5</span> <span class="p">[</span><span class="k">default</span> <span class="o">=</span> <span class="mi">1</span><span class="p">];</span>
  <span class="c1">// Specify whether to transpose the weight matrix or not.
</span>  <span class="c1">// If transpose == true, any operations will be performed on the transpose
</span>  <span class="c1">// of the weight matrix. The weight matrix itself is not going to be transposed
</span>  <span class="c1">// but rather the transfer flag of operations will be toggled accordingly.
</span>  <span class="k">optional</span> <span class="kt">bool</span> <span class="na">transpose</span> <span class="o">=</span> <span class="mi">6</span> <span class="p">[</span><span class="k">default</span> <span class="o">=</span> <span class="kc">false</span><span class="p">];</span>
<span class="p">}</span></code></pre></figure>



      </section>
  </div>
  </body>
</html>
